package com.qf.bank.cardinfoprovider.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.bank.cardinfoapi.vo.CardInfoVo;
import com.qf.bank.cardinfoprovider.mapper.CardInfoMapper;
import com.qf.bank.cardinfoprovider.service.CardInfoService;
import com.qf.bank.cardinfoapi.po.CardInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lwf
 * @since 2019-12-04
 */
@Service
public class CardInfoServiceImpl extends ServiceImpl<CardInfoMapper, CardInfo> implements CardInfoService {

    @Resource
    CardInfoMapper cardInfoMapper;

    @Override
    public List<CardInfo> getByuserName(String userName) {
        return cardInfoMapper.getByuserName(userName);
    }

    @Override
    public IPage<CardInfo> pageWithCondition(CardInfoVo cardInfoVo) {
        QueryWrapper<CardInfo> wrapper = new QueryWrapper<>();
        if (cardInfoVo != null) {
            if (cardInfoVo.getCardId() != null) {
                wrapper.lambda().eq(CardInfo::getCardId, cardInfoVo.getCardId());
            }
            if(cardInfoVo.getBank()!=null){
                wrapper.lambda().like(CardInfo::getBank,cardInfoVo.getBank());
            }
            if (cardInfoVo.getCardType()!=null){
                wrapper.lambda().like(CardInfo::getCardType,cardInfoVo.getCardType());
            }
        }
        return (Page<CardInfo>)
                baseMapper.selectPage(new Page<>(cardInfoVo.getCurrent(), cardInfoVo.getSize()), wrapper);
    }
}
